<template>
    <div>

        <el-input
        placeholder="请输入标签ID"
        v-model="datas.label_ID"
        clearable>
        </el-input>

        <br/><br/>
        <el-select v-model="goods_value" placeholder="请选择货物类型" >
            <el-option
            v-for="item in com_list"
            :key="item.id"
            :label="item.name"
            :value="item.id">
            </el-option>
        </el-select>

        <br/><br/>

       <el-select v-model="uid_value" placeholder="请选择分配用户" >
            <el-option
            v-for="item in user_list"
            :key="item.id"
            :label="item.username"
            :value="item.id">
            </el-option>
        </el-select>

        <br/><br/>
        <el-row>
        <el-button type="success"  @click="add_label">添加</el-button>
        </el-row>

        
       
    </div>
</template>



<script>
import { goods_get,Register_GET,label_post } from '../../api/api.js'
export default {
    inject:['reload'],
    data(){
        return{
            // 分配用户id    
            uid_value: '',
            // 分配货物id    
            goods_value: '',


            //货物列表
            com_list:[],
            //发送标签请求需要的参数
            datas:{
                label_ID:'',
                goods_id:'',
                assigned_users:'',
                creater_users:'',
                company_id:'',

            },
            //用户列表
            user_list:[],
        }
    },
    created() {
        this.datas.creater_users = localStorage.getItem('uid')
        this.datas.company_id = localStorage.getItem('com_id')
    },

    mounted() {
        

        //请求货物
        this.get_com()
        //请求用户
        this.get_user()
    },

    methods: {
        // 添加标签
        add_label(){
            this.datas.goods_id = this.goods_value
            this.datas.assigned_users = this.uid_value
            label_post(this.datas).then(res=>{
                if(res.code==200){
                    alert(res.message)
                    this.reload()
                }else{
                    alert(res.error)
                    this.reload()
                }
            })
        },

        //获取用户
        get_user(){
            Register_GET().then(res=>{
                // console.log(res)
                for(let i=0,l=res.data.length;i<l;i++){
                    if( res.data[i].company_id==this.datas.company_id && res.data[i].id_auditing ==1 && res.data[i].id_del==0){
                        this.user_list.push(res.data[i])
                    }
                }

            })

        },

        // 获取当前公司的货物
        get_com(){
            goods_get({com_id:localStorage.getItem('com_id')}).then(res=>{
                // console.log(res)
                this.com_list = res.data
            })
        },

       
    
        
      
      
    },
}
</script>


<style>
 

  
</style>